package com.kitty.guice;

import javax.inject.Inject;
import javax.inject.Named;
import javax.inject.Singleton;



@Singleton //标记为是否是单例.
public class HelloWorldImpl implements HelloWorld {
	/*
	 * 注入方式3种:字段注入,属性注入,构造方法注入(单一参数,多参数),
	 * 字段注入需要保证有一个无参的构造方法,
	 */
	
	@Inject  //字段注入.
	private Service service;
	public HelloWorldImpl() {
		
	}
	
	//@Inject //构造方法注入.
	public HelloWorldImpl(Service service) {
		this.service = service;
	}
	
	//@Inject  //属性注入.
	public void setService(Service service) {
		this.service = service;
	}
	
	
	public Service getService() {
		return service;
	}

	@Named("log")
	public String sayHello() {
		this.service.play();
		return "HelloWorld";
	}

}
